package net.zhengxinyun.performance.App.service.BaseIndexService;

import net.zhengxinyun.performance.Util.Util;
import net.zhengxinyun.performance.filter.CountryUnitIndicatorsFilter;
import net.zhengxinyun.performance.filter.CountryUnitScoreFilter;
import net.zhengxinyun.performance.filter.TownIndicatorsFilter;
import net.zhengxinyun.performance.filter.UserFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Component
public abstract class BaseIndexService {

    public  Logger log = LoggerFactory.getLogger(BaseIndexService.class);
    /**
     * 县对乡镇
     * @param inditors
     * @param userFilter
     * @return
     */
   public  List<TownIndicatorsFilter> filterInditors(List<TownIndicatorsFilter> inditors  , UserFilter userFilter)
    {
        String openIndeds =null;//开放的 可查看的指标
        List<TownIndicatorsFilter>  newIndisList = new ArrayList<>();
        if("admin".equals(userFilter.getUserPermissions()))
        {
            newIndisList = inditors;
        }else {
            //遍历处理可查看的指标  可查看的指标放在新的list中
            openIndeds=userFilter.getIndexRight();
            HashMap<String,Object> indexsMap = Util.getIndexIdMap(openIndeds);
            for (TownIndicatorsFilter item : inditors) {
                String id1=item.getId()+"";
                String id2=indexsMap.get(id1)+"";
                if(id1.equals(id2))
                {
                    newIndisList.add(item);
                }
            }

        }

        return newIndisList;
    }

    /**
     * 县直单位
     * @param inditors
     * @param userFilter
     * @return
     */
    public  List<CountryUnitScoreFilter> filterDeptInditors(List<CountryUnitScoreFilter> inditors  , UserFilter userFilter)
    {
        String openIndeds =null;//开放的 可查看的指标
        List<CountryUnitScoreFilter>  newIndisList = new ArrayList<>();
        if("admin".equals(userFilter.getUserPermissions()))
        {
            newIndisList = inditors;
        }else {
            //遍历处理可查看的指标  可查看的指标放在新的list中
            openIndeds=userFilter.getDepartIndex();
            HashMap<String,Object> indexsMap = Util.getIndexIdMap(openIndeds);
            for (CountryUnitScoreFilter item : inditors) {
                String id1=item.getId()+"";
                String id2=indexsMap.get(id1)+"";
                if(id1.equals(id2))
                {
                    newIndisList.add(item);
                }
            }

        }

        return newIndisList;
    }



}
